#!/bin/sh
cd `dirname $0`
#容器名称每个人修改为自己的
contrainsname="ldt.commoncapacitysupport"
contrainshave=`docker ps -a --filter name=$contrainsname --filter status=running`
if [[ $contrainshave == *$contrainsname* ]]
then
    echo "$contrainsname 容器正在运行"
else
	contrainshave=`docker ps -a --filter name=$contrainsname`
	if [[ $contrainshave == *$contrainsname* ]]
	then
		echo "$contrainsname 容器已经存在，开始启动"
		docker start $contrainsname
	else
		echo "$contrainsname 容器不存在，开始创建"
		#修改dll的目录名称、dll的名称
		dlldir="/home/ldt/judger/ldt.commoncapacitysupport"
		dllname="Ldt.CommonCapacitySupport.dll"
		#修改-p对应的参数为自己的端口号--restart=always
		docker run --ulimit core=0 --privileged=true -p 18000:18000 -v  $dlldir:$dlldir -v /home/ldt/ldt.judgetdoc.log:/home/ldt/ldt.judgetdoc.log -w $dlldir  --name $contrainsname -d -v /etc/localtime:/etc/localtime:ro mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic dotnet $dllname
	fi	
	contrainshave=`docker ps -a --filter name=$contrainsname --filter status=running`
	if [[ $contrainshave == *$contrainsname* ]]
	then
		echo "$contrainsname 容器启动成功，开始运行"
	else
		echo "$contrainsname 容器启动失败"
		docker rm $contrainsname
		exit 1		
	fi		
fi